//
//  DownloadTargetType.swift
//  DaRings
//
//  Created by 尹琼 on 2022/11/25.
//

import UIKit
import Moya


public enum DownloadTargetType {
    
    /// 文件下载
    case download(url: String, filePath: String)
    
}

extension DownloadTargetType: APITargetType {
    
    public var baseURL: URL {
        switch self {
        case .download(let url, _):
            return URL(string: url)!
        }
    }
    public var path: String {
        switch self {
        case .download(_, _):
            return ""
        }
    }
    public var method: Moya.Method {
        switch self {
        case .download(_, _):
            return .get
        }
    }
    
    public var task: Task {
        switch self {
        case .download(_, _):
            return .downloadDestination(downloadDestination)
        }
    }
    
    public var localLocation: URL {
           switch self {
           case .download(_, let filePath):
               return URL(fileURLWithPath: filePath)
           }
       }
       
       public var downloadDestination: DownloadDestination {
          
           return { _, _ in return (self.localLocation, [.removePreviousFile, .createIntermediateDirectories]) }
       }
    
}


